package com.developer.platform.application.query.assembler;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.developer.platform.application.query.dto.GroupDto;
import com.developer.platform.application.query.dto.ResponseModel;
import com.developer.platform.domain.Group;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2020-12-29
 */
@Component
public class GroupAssembler extends BaseAssembler{

  public GroupDto toGroupDto(Group group){
    GroupDto groupDto = new GroupDto();
    BeanUtil.copyProperties(group, groupDto);
    return groupDto;
  }

  public ResponseModel<GroupDto> toGroupDtoPage(IPage<Group> page){
    List<GroupDto> collect = page.getRecords().stream().map(this::toGroupDto)
        .collect(Collectors.toList());
    this.userName(collect);
    return new ResponseModel<>(collect, (int)page.getTotal());
  }

}
